|
|
|
|
|
|
|
In this picture, the triangles DABP and DAOP' have the same angles, so they are similar triangles. The ratio of corresponding side lengths in similar triangles must be the same, so |OP'| / |AO| = |BP| / |AB|. At the left part of Figure 13.21, you can see that |OP'| = P'y, |AO| = d, |BP| = Py, and |AB| = (d - Pz), so P'y/d = Py/(d - Pz). Solving for P'y, you get P'y = d * Py/(d Pz). This gives the projected point's Y coordinate. |
|
|
|
|
|
|
|
|
By examining a similar picture showing the X and Z axes, you can find that P'x = d * Px/(d - Pz). Using these facts, you can conclude that the equations for perspective projection onto the X-Y plane where the center of projection lies at position (0, 0, d) are: |
|
|
|
 |
|
|
|
|
new_x = d * (old_y) / (d - (old_z))
new_y = d * (old_x) / (d - (old_z))
new_z = 0 |
|
|
|
|
|
|
|
|
You can represent these equations with the transformation matrix: |
|
|
|
|
|
|
|
|
When you multiply a point (x, y, z, 1) by this matrix you get: |
|
|
|
|
|
|
|
|
Remember that the fourth component in a homogeneous representation of a point is a scale factor. If you normalize the point [x, y, 0, 1 z/d] by dividing by the fourth component 1 z/d, the point becomes: |
|
|
|
 |
|
|
|
|
[x / (1 - z / d), y / (1 - z / d), 0, 1] =
[d * x / (d - z), d * y / (d - y), 0, 1] |
|
|
|
|
|
|
|
|
This agrees with the previous equations for the new values of x, y, and z. |
|
|
|
|
|
|
|
|
Using the perspective projection matrix shown here, you can easily write a Visual Basic routine that initializes a transformation matrix that projects onto the X-Z plane. |
|
|
|
 |
|
|
|
|
' Create a 3-D transformation matrix for a
' perspective projection into the X-Z plane with
' center of projection at the origin and the plane
' of projection at distance D. Public Sub m3PerspectiveXZ(M() As Single, ByVal D As Single)
m3Identity M
If D <> 0 Then
M(3, 4) = -1 / D
M(3, 3) = 0 |
|
|
|
|
|